﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.ReportSource;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Windows.Forms;


namespace WP09S03_OfficeTracking.Controller
{
    class ReportController : ParentClass.ParentController 
    {

        public ReportController()
            : base()
        {
        }


        public void GetAllEmployeesData(CrystalReportViewer viewer)
        {
              DAL.DSEmployee ds = new DAL.DSEmployee();
              DAL.DSEmployeeTableAdapters.EmployeeTableAdapter da = new DAL.DSEmployeeTableAdapters.EmployeeTableAdapter();
              da.Fill(ds.Employee); 
              Reports.CrystalReportEmployees r = new Reports.CrystalReportEmployees();
              r.SetDataSource(ds);
              viewer.ReportSource = r;
        }

        public void GetAllBooksAndEquipments(CrystalReportViewer viewer)
        {
            DAL.DSReport ds = new DAL.DSReport();
            DAL.DSReportTableAdapters.AllItemsInfoTableAdapter da = new DAL.DSReportTableAdapters.AllItemsInfoTableAdapter();
            da.FillAllBooksAndEquip(ds.AllItemsInfo); 
            Reports.CrystalReportBooksEquip r = new Reports.CrystalReportBooksEquip();
            r.SetDataSource(ds);
            viewer.ReportSource = r;
        }
        
        public void GetAllSupplies(CrystalReportViewer viewer)
        {
            DAL.DSReport ds = new DAL.DSReport();
            DAL.DSReportTableAdapters.AllItemsInfoTableAdapter da = new DAL.DSReportTableAdapters.AllItemsInfoTableAdapter();
            da.FillAllSupplies(ds.AllItemsInfo);
            Reports.CrystalReportSupplies r = new Reports.CrystalReportSupplies();
            r.SetDataSource(ds);
            viewer.ReportSource = r;
        }

        public void GetSuppliesToBeReplenished(CrystalReportViewer viewer)
        {
            DAL.DSReport ds = new DAL.DSReport();
            DAL.DSReportTableAdapters.AllItemsInfoTableAdapter da = new DAL.DSReportTableAdapters.AllItemsInfoTableAdapter();
            da.FillItemsToReplenish(ds.AllItemsInfo);
            Reports.CrystalReportSupplies r = new Reports.CrystalReportSupplies();
            r.SetDataSource(ds);
            viewer.ReportSource = r;
        }

        public void GetBorrowedBooksAndEquipPerEmployee(CrystalReportViewer viewer)
        {
            DAL.DSReport ds = new DAL.DSReport();
            DAL.DSReportTableAdapters.OverdueItemsTableAdapter da = new DAL.DSReportTableAdapters.OverdueItemsTableAdapter();
            ds.EnforceConstraints = false;
            da.FillBorrowedItems(ds.OverdueItems);
            //Report will group by employee
            Reports.CrystalReportBorrowedItems r = new Reports.CrystalReportBorrowedItems();
            r.SetDataSource(ds);
            viewer.ReportSource = r;
        }

        public void GetOverdueBooksAndEquip(CrystalReportViewer viewer)
        {
            DAL.DSReport ds = new DAL.DSReport();
            DAL.DSReportTableAdapters.OverdueItemsTableAdapter da = new DAL.DSReportTableAdapters.OverdueItemsTableAdapter();
            ds.EnforceConstraints = false;
            da.FillBorrowedItems(ds.OverdueItems);
            //Report will filter if enddate was yesterday
            Reports.CrystalReportOverdueItems r = new Reports.CrystalReportOverdueItems();
            r.SetDataSource(ds);
            viewer.ReportSource = r;
        }


        public void GetEmployeesSuppliesCost(CrystalReportViewer viewer)
        {
            DAL.DSReport ds = new DAL.DSReport();
            DAL.DSReportTableAdapters.SuppliesConsumedInfoTableAdapter da = new DAL.DSReportTableAdapters.SuppliesConsumedInfoTableAdapter();
            da.FillSuppliesConsumedInfo(ds.SuppliesConsumedInfo);
            //Report will filter if enddate was yesterday
            Reports.CrystalReportEmployeesSuppliesCost r = new Reports.CrystalReportEmployeesSuppliesCost();
            r.SetDataSource(ds);
            viewer.ReportSource = r;
        }

        public void GetMonthlyCost(CrystalReportViewer viewer)
        {
            DAL.DSReport ds = new DAL.DSReport();
            DAL.DSReportTableAdapters.SuppliesConsumedInfoTableAdapter da = new DAL.DSReportTableAdapters.SuppliesConsumedInfoTableAdapter();
            da.FillSuppliesConsumedInfo(ds.SuppliesConsumedInfo);
            //Report will filter if enddate was yesterday
            Reports.CrystalReportItemCosts r = new Reports.CrystalReportItemCosts();
            r.SetDataSource(ds);
            viewer.ReportSource = r;
        }

        public void GetIssueTransaction(CrystalReportViewer viewer, System.Nullable<System.DateTime> usedStartTimeFrom, System.Nullable<System.DateTime> usedStartTimeTo, System.Nullable<System.DateTime> usedEndTimeFrom, System.Nullable<System.DateTime> usedEndTimeTo)
        {
            //DAL.DSTransactionTableAdapters.vw_IssueTransactionTableAdapter adapter = new WP09S03_OfficeTracking.DAL.DSTransactionTableAdapters.vw_IssueTransactionTableAdapter();
            //DAL.DSTransaction.vw_IssueTransactionDataTable table = new WP09S03_OfficeTracking.DAL.DSTransaction.vw_IssueTransactionDataTable();
            //table = adapter.GetDataBy("", "", "", usedStartTimeFrom, usedStartTimeTo, usedEndTimeFrom, usedEndTimeTo, "", "", "", "", "", "", "");
            DAL.DSTransaction ds = new DAL.DSTransaction();
            DAL.DSTransactionTableAdapters.vw_IssueTransactionTableAdapter da = new WP09S03_OfficeTracking.DAL.DSTransactionTableAdapters.vw_IssueTransactionTableAdapter();

            da.FillBy(ds.vw_IssueTransaction,"", "", "", usedStartTimeFrom, usedStartTimeTo, usedEndTimeFrom, usedEndTimeTo, "", "", "", "", "", "", "");
            Reports.CrystalReportIssueTransaction r = new Reports.CrystalReportIssueTransaction();
            r.SetDataSource(ds);
            viewer.ReportSource = r;
        }

        public void GetReturnTransaction(CrystalReportViewer viewer, System.Nullable<System.DateTime> createTimeFrom, System.Nullable<System.DateTime> createTimeTo)
        {
            DAL.DSTransaction ds = new DAL.DSTransaction();
            DAL.DSTransactionTableAdapters.vw_ReturnTransactionTableAdapter da = new WP09S03_OfficeTracking.DAL.DSTransactionTableAdapters.vw_ReturnTransactionTableAdapter();

            da.FillBy(ds.vw_ReturnTransaction, "", createTimeFrom, createTimeTo,"","","","","","","");
            Reports.CrystalReportReturnTransaction r = new Reports.CrystalReportReturnTransaction();
            r.SetDataSource(ds);
            viewer.ReportSource = r;
        }

        public void GetReplenishTransaction(CrystalReportViewer viewer, System.Nullable<System.DateTime> createTimeFrom, System.Nullable<System.DateTime> createTimeTo)
        {
            DAL.DSTransaction ds = new DAL.DSTransaction();
            DAL.DSTransactionTableAdapters.vw_ReplenishTransactionTableAdapter da = new WP09S03_OfficeTracking.DAL.DSTransactionTableAdapters.vw_ReplenishTransactionTableAdapter();

            da.FillBy(ds.vw_ReplenishTransaction, "", createTimeFrom, createTimeTo, "", "", "", "", "");
            Reports.CrystalReportReplenishTransaction r = new Reports.CrystalReportReplenishTransaction();
            r.SetDataSource(ds);
            viewer.ReportSource = r;
        }

    }
}
